<?php
/**********************************************
 *     ┌─┐       ┌─┐ + +
 *  ┌──┘ ┴───────┘ ┴──┐++
 *  │                 │
 *  │       ───       │++ + + +
 *  ███████───███████ │+
 *  │                 │+
 *  │       ─┴─       │
 *  │                 │
 *  └───┐         ┌───┘
 *      │         │
 *      │         │   + +
 *      │         │
 *      │         └──────────────┐
 *      │                        │
 *      │                        ├─┐
 *      │                        ┌─┘
 *      │                        │
 *      └─┐  ┐  ┌───────┬──┐  ┌──┘  + + + +
 *        │ ─┤ ─┤       │ ─┤ ─┤
 *        └──┴──┘       └──┴──┘  + + + +
 *          神兽保佑 代码无BUG!
 * ——————————————————————————————————————————
 * 创建时间 2025年05月2025/5/21日 00:00
 * wechat:note744917
 * email:sunjinglong@lingyier.com
 * ——————————————————————————————————————————
 */

namespace SunAdmin\Controller;

use SunAdmin\Common\ResponseJson;
use SunAdmin\Service\AttachmentService;

class AttachmentController {
	public function upload() {
		$file = request()->file('file');
		$uploadRes = AttachmentService::upload($file,'admin',request()->adminUid);
		if($uploadRes['status']){
			return ResponseJson::success($uploadRes['data'],$uploadRes['message']);
		}
		return ResponseJson::error($uploadRes['message'], 500, $uploadRes['data']);
	}

    public function delete()
    {
        $ids = request()->param('ids');
        AttachmentService::delete($ids);
        return ResponseJson::success('删除成功');
    }
    public function getList(){
        $where = request()->param('where');
        $page = request()->param('page',1);
        $limit = request()->param('limit',20);
        $res = AttachmentService::getList($where,$page,$limit);
        return ResponseJson::success($res);
    }

    public function getUploadConfig()
    {
        $config = AttachmentService::getUploadConfig();
        return ResponseJson::success($config);
    }

    /**
     * 获取文件系统配置列表
     */
    public function getFilesystemConfigs()
    {
        $configs = AttachmentService::getFilesystemConfigs();
        return ResponseJson::success($configs);
    }

    /**
     * 更新文件系统配置
     */
    public function updateFilesystemConfig()
    {
        $data = request()->param();
        AttachmentService::updateFilesystemConfig($data);
        return ResponseJson::success('配置更新成功');
    }
}